CoAP Package : CoAP package interfaces

更新时间:
2024-05-13
下载文档

CoAP Package : CoAP package interfaces

The CoapPackage class describes the CoAP protocol format and provides operation interfaces for protocol settings. Both the client and server can access CoAP data through this type of object.

Support

The following shows CoapPackage module APIs available for each permissions.

 User ModePrivilege Mode
package.remote
package.token
package.options
package.payload
package.code
package.path
package.method
package.setOption
package.appendOption
package.setOptions
package.getOption
package.setPayload
package.appendPayload
package.isConfirm

Package Object

package.remote

  • {Object} Server socket address.

package.token

  • {Buffer} Message token, Identify resources requested.

package.options

  • {Object} Coap options. See APIs:
    • package.setOption
    • package.appendOption
    • package.setOptions
    • package.getOption

package.payload

  • {String | Buffer} Coap payload to be send or received.

package.code

  • {String} Code request method code for request and response status code for response. Details:

    CodeDescription
    2.01Created.
    2.02Deleted.
    2.03Valid.
    2.04Changed.
    2.05Content.
    4.00Bad Request.
    4.01Unauthorized.
    4.02Bad Option.
    4.03Forbidden.
    4.04Not Found.
    4.05Method Not Allowed.
    4.06Not Acceptable.
    4.12Precondition Failed.
    4.13Request Entity Too Large.
    4.15Unsupported Content-Format.
    5.00Internal Server Error.
    5.01Not Implemented.
    5.02Bad Gateway.
    5.03Service Unavailable.
    5.04Gateway Timeout.
    5.05Proxying Not Supported.

package.path

  • {Stiring} Coap Uri-Path.

package.method

  • {String} Coap request method. Coap support method:
    • GET
    • POST
    • PUT
    • DELETE

package.setOption(key[, val])

  • key {String} Option name.
  • val * {Any | Undefined}* Option value. If val equal undefined, this option will be removed.

Set or remove package option. The coap option details:

No.NameFormatLengthDefault
1If-Matchopaque0-8(none)
3Uri-Hoststring1-255(#)
4ETagopaque1-8(none)
5If-None-Matchempty0(none)
7Uri-Portuint0-2(#)
8Location-Pathstring0-255(none)
11Uri-Pathstring0-255(none)
12Content-Formatuint0-2(none)
14Max-Ageuint0-460
15Uri-Querystring0-255(none)
17Acceptuint0-2(none)
20Location-Querystring0-255(none)
35Proxy-Uristring1-1034(none)
39Proxy-Schemestring1-255(none)
60Sizeluint0-4(none)

package.appendOption(key, val)

  • key {String} Option name.
  • val * {Any | Array}* Option value.

Add or append package option.

package.setOptions(opts)

  • opts {Object} Coap options,

Set multiple options.

package.getOption(key)

  • key {String} Option name.
  • Returns: {Undefined | Array | Any} Option value.

Get option value.

package.setPayload([chunk])

  • chunk {Undefined | String | Buffer | Object} Payload data. If chunk undefined, payload set to undefined.

Set package payload.

package.appendPayload(chunk)

  • chunk {String | Buffer | Object} Payload data.
  • Returns: {Boolean} Append payload success or not.

Set or append package payload. This api can be call multiple times.

package.isConfirm()

  • Returns: {Boolean} The request is confirm or no.

Confirm(CON): A request that needs to be acknowledged. If a CON request is sent, the other party must respond. This request is used for reliable transmission.

No confirm(NON): There is no need to confirm the request, if the NON request is sent, then the other party does not have to respond. This request is unreliable.

文档内容是否对您有所帮助?
有帮助
没帮助